import java.awt.Image;


public abstract class Bird {

	public static final int COLIBRIS_TYPE = 1;
	public static final int MOINEAUX_TYPE = 2;
	public static final int PIGEON_TYPE = 3;

	private int type;	
	protected Image[] imageArray = new Image[2];
	protected Image currentImage;

	protected int orientation;
	private double posX;
	private double posY;

	protected int imageWidth;
	protected int imageHeight;
	protected double speed;
	protected int time;

	public boolean hasPlayed = false;

	private long timeWhenPaused = 0;
	private long timeCreation = System.currentTimeMillis()/1000;
	private long TimeLeftWhenPaused;

	public abstract void setSpeedCoef(double d);
	
	public 			Bird(int type) {
		this.type = type;
		this.orientation = 0;
		this.posX = Windows.WIDTH/2;
		this.posY = -20;
	}

	public long getTimeLeftWhenPaused(){
		if(this.hasPlayed)
			return this.TimeLeftWhenPaused;
		else
			return this.time;
	}

	public void 	resumeTimer(){
		this.timeCreation = this.timeCreation - (this.timeWhenPaused - (System.currentTimeMillis()/1000));
	}

	public void 	pauseTimer() {
		this.TimeLeftWhenPaused = this.getTimeleft();
		this.timeWhenPaused = System.currentTimeMillis()/1000;
	}

	public long 	getTimeleft(){
		return (this.time - ((System.currentTimeMillis()/1000) - this.timeCreation));
	}

	public void 	changeOrientation(int orientation){
		if(orientation == 1){
			this.currentImage = this.imageArray[0];
			this.orientation = 1;
		}
		else if(orientation == -1){
			this.currentImage = this.imageArray[1];
			this.orientation = -1;
		}
		else{
			this.orientation = 0;
		}
	}

	public void 	nextStep(){
		if(this.orientation == -1)
			goLeft();
		else if(this.orientation == 1)
			goRight();
	}

	private void 	goLeft(){
		this.posX -= this.speed;
		if(this.posX < 0)
			posX = 0;
	}

	private void 	goRight(){
		this.posX += this.speed;
		if(this.posX + this.imageWidth > Windows.WIDTH)
			this.posX = Windows.WIDTH - this.imageWidth;
	}

	public void		changeY(int val){
		if(val >= -1 && val <= 1)
			this.posY += 2*val;
	}

	public void 	resetCreatedAt() {
		this.timeCreation = (System.currentTimeMillis()/1000);
	}

	public int 		getType() {
		return this.type;
	}

	public double 	getSpeed(){
		return this.speed;
	}

	public Image 	getImage() {
		return this.currentImage;
	}

	public double	getX(){
		return this.posX;
	}

	public double	getY(){
		return this.posY;
	}
}
